{% set pypi_name = 'stackviz' %}
{% set source = fetch_source('https://tarballs.openstack.org/stackviz/stackviz-master.tar.gz') %}
{% set upstream_version = upstream_version() %}
{% set rpm_release = '1' %}
%global common_desc \
A visualization utility to help analyze the performance of \
DevStack setup and Tempest executions
%global with_doc 1
%global with_tests 1
Name:           {{ py2name() }}
Version:        {{ py2rpmversion() }}
Release:        {{ py2rpmrelease() }}
Summary:        Visualization utility
License:        {{ license('Apache-2.0') }}
URL:            https://docs.openstack.org/stackviz/
Source0:        {{ source|basename }}
BuildRequires:  openstack-macros
BuildRequires:  {{ py3('devel') }}
BuildRequires:  {{ py3('oslotest') }}
BuildRequires:  {{ py3('python-subunit') }}
BuildRequires:  {{ py3('stestr') }}
BuildRequires:  {{ py3('testrepository') }}
BuildRequires:  {{ py3('testtools') }}
BuildArch:      noarch
%if 0%{?rdo}
Requires:       {{ py3('subunit2sql') }}
%endif
%if 0%{?with_tests}
BuildRequires:  {{ py3('docutils') }}
%endif

%description
%{common_desc}

%package -n {{ py2name(py_versions='py3') }}
Summary:        Visualization utility
Requires:       {{ py3('python-subunit') }}
Requires:       {{ py3('six') }}
Requires:       {{ py3('testrepository') }}
Requires:       {{ py3('testtools') }}
%if 0%{?rdo}
Requires:       {{ py3('subunit2sql') }}
%endif

%description -n {{ py2name(py_versions='py3') }}
%{common_desc}

This package contains the Python 3.x module.

%if 0%{?with_doc}
%package -n python-stackviz-doc
Summary:        Documentation for stackviz
BuildRequires:  {{ py3('Sphinx') }}
BuildRequires:  {{ py3('openstackdocstheme') }}
BuildRequires:  {{ py3('sphinxcontrib-svg2pdfconverter') }}

%description -n python-stackviz-doc
It contains the documentation for the stackviz.
%endif


%prep
%autosetup -n {{ pypi_name }}-{{ upstream_version }}
%py_req_cleanup

%build
%{py3_build}

# Generate Docs
%if 0%{?with_doc}
export PYTHONPATH="$( pwd ):$PYTHONPATH"
PBR_VERSION={{ upstream_version }} %sphinx_build -b html doc/source doc/build/html
# remove the sphinx-build leftovers
rm -rf doc/build/html/.{doctrees,buildinfo}
%endif

%install
%{py3_install}

%if 0%{?with_tests}
%check
export OS_TEST_PATH=./stackviz/tests
export PYTHONPATH=.
python3 -m stestr.cli run
%endif


%files -n {{ py2name(py_versions='py3') }}
%license LICENSE
%{_bindir}/stackviz-export
%{python3_sitelib}/stackviz
%{python3_sitelib}/stackviz-*.egg-info

%if 0%{?with_doc}
%files -n python-stackviz-doc
%license LICENSE
%doc doc/build/html
%endif

%changelog
